<!-- /** -->
 * 会员浮动
 */
<template>
  <div>
    <div v-if="isUser">
      <!-- 面包屑导航 -->
      <el-breadcrumb separator-class="el-icon-arrow-right" class="margin-t10">
        <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
        <el-breadcrumb-item>会员浮动费率</el-breadcrumb-item>
      </el-breadcrumb>
      <div class="boxBlock"> 
        <div class="serachTop"> 
             <!-- 搜索筛选 -->
            <el-form :inline="true" :model="formInline" class="user-search">
              <el-form-item >
                <el-input
                  size="small"
                  v-model="formInline.userId"
                  placeholder="输入账号ID"
                  type="number"
                  clearable
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-input
                  size="small"
                  v-model="formInline.loginName"
                  placeholder="输入账号名称"
                  clearable
                ></el-input>
              </el-form-item>
              <el-form-item>
                <el-select
                  size="small"
                  v-model="formInline.authType"
                  placeholder="请选择认证状态"
                  clearable
                >
                  <el-option label="请选择认证状态" value=""></el-option>
                  <el-option
                    v-for="type in statusData"
                    :label="type.key"
                    :value="type.value"
                    :key="type.value"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item>
                <el-button
                  size="small"
                  type="primary"
                  icon="el-icon-search"
                  @click="search"
                >
                  搜索
                </el-button>
              </el-form-item>
            </el-form>
        </div>
     
     
      <!--列表-->
      <div class="ra_box">
        <el-table
          size="small"
          :data="listData"
          highlight-current-row
          v-loading="loading"
          element-loading-text="拼命加载中"
          style="width: 100%"
        >
          <el-table-column prop="userId" label="用户ID" width="80" fixed="left" >
          </el-table-column>
          <el-table-column prop="params.iamCount" label="IAM" width="120"> </el-table-column> 
          <el-table-column
            prop="loginName"
            label="账户名称"
            show-overflow-tooltip
          >
          </el-table-column>
          <el-table-column prop="userName" label="昵称" show-overflow-tooltip>
          </el-table-column>
          <el-table-column
            prop="balance"
            label="账户余额"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <div>{{ b(scope.row.balance) }}</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="cardBalance"
            label="卡余额"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <div>
                {{
                  b(
                    scope.row.params.cardBalance
                      ? scope.row.params.cardBalance
                      : 0
                  )
                }}
              </div>
            </template>
          </el-table-column>
          <el-table-column prop="count" label="卡Bin" show-overflow-tooltip>
            <template slot-scope="scope">
              <div>{{ scope.row.params.count }}</div>
            </template>
          </el-table-column>
          <!-- <el-table-column
            prop="refuseCount"
            label="拒付率"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <div>
                {{
                  scope.row.params.transactionCount == 0
                    ? "0%"
                    : (
                        (scope.row.params.refuseCount /
                          scope.row.params.transactionCount) *
                        100
                      ).toFixed(0) + "%"
                }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="refundCount"
            label="退款率"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <div>
                {{
                  scope.row.params.transactionCount == 0
                    ? "0%"
                    : (
                        (scope.row.params.refundCount /
                          scope.row.params.transactionCount) *
                        100
                      ).toFixed(0) + "%"
                }}
              </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="refundAmount"
            label="退款金额率"
            show-overflow-tooltip
            width="160"
          >
            <template slot-scope="scope">
              <div>
                {{
                  scope.row.params.transactionAmount == 0
                    ? "0%"
                    : (
                        (scope.row.params.refundAmount /
                          scope.row.params.transactionAmount) *
                        100
                      ).toFixed(0) + "%"
                }}
              </div>
            </template>
          </el-table-column> -->
          <!-- <el-table-column
            prop="shareCardCount"
            label="配置共享卡"
            show-overflow-tooltip
            v-if="hasPermissionMethod(['admin7'])"  
            width="160"
          >
            <template slot-scope="scope">
              <i
                class="el-icon-edit-outline font18 font-w6 margin-l5"
                @click="handleShare(scope.$index, scope.row)"
              >
              </i>
              {{ scope.row.shareCardCount }}
            </template>
          </el-table-column> -->
          
          <!-- <el-table-column
            prop="authType"
            label="是否为代理商"  width="260"
          >
            <template slot-scope="scope"> 
              <el-switch
                v-model="scope.row.agent"
                active-color="#e3b85a"
                :width="60"
                :activeValue="true"
                :inactiveValue="false" 
                @change="changeSwitch($event,scope.row)"
                :disabled="scope.row.authType==2&&scope.row.invitationCode==1?false:true"
                inactive-color="#eeeeee">
              </el-switch>

              <span v-if="scope.row.agent==1">  
                <el-tooltip class="item" effect="dark" content="复制链接注册会员后成为该客户的下级客户" placement="top">
                    <el-button
                      size="mini" plain 
                      v-copy="`${hostname}#/register?invitationCode=${scope.row.userId}`"  
                    >
                    复制
                  </el-button>
                </el-tooltip> 
              </span> 
            </template>
          </el-table-column>  -->
          <el-table-column
            prop="params.agentCount"
            label="代理商数量"  width="160"
          >
          </el-table-column>
          <el-table-column
            prop=" invitationCode"
            label="上级代理"  width="160"
          >
            <template slot-scope="scope">
              {{  scope.row.invitationCode==1?'平台':scope.row.invitationCode }}
            </template> 
          </el-table-column>

          
          <el-table-column
            prop="authType"
            label="企业认证"
            show-overflow-tooltip
          >
            <template slot-scope="scope">
              <div>{{ statusJson[scope.row.authType].key }}</div>
            </template>
          </el-table-column>
          <el-table-column
            prop="createTime"
            label="创建时间"
            show-overflow-tooltip
          >
          </el-table-column> 

          <!-- <el-table-column prop="remark" label="备注" show-overflow-tooltip>
        </el-table-column> -->
          <el-table-column align="center" fixed="right" label="操作" width="180">
            <template slot-scope="scope">
              <!-- <el-button size="mini" plain @click="changUser(false, scope.row)"   v-if="hasPermission5">
                查看
              </el-button> -->
              <!-- <el-button
                size="mini"
                type="success"
                @click="handleShare(scope.$index, scope.row)"
              >
                共享卡
              </el-button> -->
              <!-- <el-button
                size="mini"
                plain
                @click="handleReset(scope.$index, scope.row)"
                style="color: #999; cursor: pointer;" v-if="hasPermission5"
              >
                重置 
              </el-button> -->
              <!-- <el-button
                size="mini"
                
                @click="handleEdit(scope.$index, scope.row)"
                style="color: #67C23A; cursor: pointer;"   v-if="hasPermission6"
              >
                充值
              </el-button>
              <el-button
                size="mini"
               
                @click="handleCut(scope.$index, scope.row)"   v-if="hasPermission6"
              >
                扣款
              </el-button> 

              <el-button size="mini"  @click="handleUser(scope.$index, scope.row)" v-if="hasPermission5"> 
                 <label v-if="scope.row.status == 1" style="color: #67C23A; cursor: pointer;">启用</label>
                 <label v-if="scope.row.status == 0" style="color: #f74e4e; cursor: pointer;">停用</label>
              </el-button> 
              <el-button
                size="mini" 
                @click="delUser(scope.$index, scope.row)"
                style="color: #f74e4e; cursor: pointer;"
                v-if="hasPerDel" 
              >
                删除
              </el-button> -->

              <el-button
                size="mini" 
                type="primary"
                @click="peizhi(scope.$index, scope.row)" 
                style="color: #fff; cursor: pointer;"  
              >
                配置
              </el-button> 
            
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 分页组件 -->
      <Pagination
        v-bind:child-msg="pageparm"
        @callFather="callFather"
      ></Pagination>
    </div>
      <!-- 充值界面 -->
      <el-dialog
        :close-on-click-modal="false"
        title="充值"
        :visible.sync="addFormVisible"
        width="30%"
        @close="closeDialog('addForm')"
      >
        <el-form
          :model="addForm"
          :rules="rulesAdd"
          ref="addForm"
          label-width="100px"
          label-position="left"
          style="50%"
        >
          <el-form-item label="充值金额" prop="rechargeAmount" class="wid-9">
            <el-input
              size="small"
              v-model="addForm.rechargeAmount"
              auto-complete="off"
              placeholder="请输入充值金额xxx"
            ></el-input>
          </el-form-item>
          <el-form-item label="到账金额" prop="amount" class="wid-9">
            <el-input
              size="small"
              v-model="addForm.amount"
              auto-complete="off"
              placeholder="请输入到账xxx"
            ></el-input>
          </el-form-item>
          <el-form-item label="备注" prop="remark" class="wid-9">
            <el-input
              size="small"
              v-model.trim="addForm.remark"
              auto-complete="off"
              type="textarea"
              :rows="5"
              placeholder="请输入备注"
            ></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="closeDialog()">取消</el-button>
          <el-button
            size="small"
            type="primary"
            :loading="loading"
            class="title"
            @click="submitFormAdd()"
            :disabled="disabled"
            >充值</el-button
          >
        </div>
      </el-dialog>
      <!-- 扣款界面 -->
      <el-dialog
        :close-on-click-modal="false"
        title="扣款"
        :visible.sync="cutFormVisible"
        width="30%"
        @close="closeDialog('cutForm')"
      >
        <el-form
          :model="cutForm"
          :rules="rulesCut"
          ref="cutForm"
          label-width="100px"
          label-position="left"
          style="50%"
        >
          <el-form-item
            label="账户余额"
            prop="balance"
            v-if="uitemInfo"
            class="wid-10"
          >
            {{ b(uitemInfo.balance) }}
          </el-form-item>
          <el-form-item label="扣款金额" prop="amount" class="wid-9">
            <el-input
              size="small"
              v-model="cutForm.amount"
              auto-complete="off"
              placeholder="请输入扣款金额xxx"
            ></el-input>
          </el-form-item>
          <el-form-item label="备注" prop="remark" class="wid-9">
            <el-input
              size="small"
              v-model.trim="cutForm.remark"
              auto-complete="off"
              type="textarea"
              :rows="5"
              placeholder="请输入备注"
            ></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="closeDialog('cutForm')">
            取消
          </el-button>
          <el-button
            size="small"
            type="primary"
            :loading="loading"
            class="title"
            @click="submitFormCut()"
            :disabled="disabled"
            >提交</el-button
          >
        </div>
      </el-dialog>
      <!-- 重置密码  -->
      <el-dialog
        :close-on-click-modal="false"
        title="重置密码"
        :visible.sync="resetFormVisible"
        width="30%"
        @close="closeDialog"
      >
        <el-form
          :model="resetForm"
          :rules="rulesReset"
          ref="resetForm"
          label-width="120px"
          label-position="left"
          style="50%"
        >
          <el-form-item label="新密码" prop="password">
            <el-input
              size="small"
              show-password
              v-model="resetForm.password"
              auto-complete="off"
              placeholder="请输入新密码"
            ></el-input>
          </el-form-item>
          <el-form-item label="再次确认密码" prop="confirmPassword">
            <el-input
              size="small"
              v-model="resetForm.confirmPassword"
              auto-complete="off"
              show-password
              placeholder="请再次确认密码"
            ></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="closeDialog('resetForm')"
            >取消</el-button
          >
          <el-button
            size="small"
            type="primary"
            :loading="loading"
            class="title"
            @click="submitFormReset()"
            :disabled="disabled"
            >提交</el-button
          >
        </div>
      </el-dialog>
      <!-- 共享卡  -->
      <el-dialog
        :close-on-click-modal="false"
        title="配置共享卡"
        :visible.sync="shareFormVisible"
        width="30%"
        @close="closeDialog('shareForm')"
      >
        <el-form
          :model="shareForm"
          :rules="rulesShare"
          ref="shareForm"
          label-width="150px"
          label-position="left"
          style="50%"
        >
          <el-form-item label="可开通共享卡" prop="shareCardCount">
            <el-input
              size="small"
              v-model="shareForm.shareCardCount"
              auto-complete="off"
              placeholder="请输入可开通共享卡数量"
            ></el-input>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button size="small" @click="closeDialog('shareForm')"
            >取消</el-button
          >
          <el-button
            size="small"
            type="primary"
            :loading="loading"
            class="title"
            @click="submitFormShare()"
            :disabled="disabled"
            >提交</el-button
          >
        </div>
      </el-dialog>


      <el-dialog
        :close-on-click-modal="false"
        title="配置"
        :visible.sync="addFormVisiblePei"
        width="900px"
        @close="closeDialog"
        >

        <el-alert
            show-icon
            title="固定金额收费填写数字，比如收费5U，填写5；比例收费时填写百分比，比如收费交易金额的10%，填写10%。月租服务费仅支持固定金额"
            type="error">
        </el-alert> 
 

        <el-form
            :model="addForm"
            :rules="rules"
            label-width="200px"
            ref="addForm"
            class="myForm"
        >
    
                <el-form-item label="操作人"  > 
                {{ addForm.createBy || '-' }}
                </el-form-item>
                <el-form-item label="更新时间"  > 
                {{    timestampToTime(addForm.updateAt, 8 * 60 * 60)  || '-' }}
                </el-form-item>  
                <el-form-item label="开卡手续费" prop="open"  style="margin-top: 20px;">
                <el-input
                    size="small"
                    v-model="addForm.open"
                    auto-complete="off"
                    placeholder="请输入开卡手续费"
                ></el-input>
                </el-form-item>
                <el-form-item label="卡充值手续费" prop="recharge" >
                <el-input
                    size="small"
                    v-model="addForm.recharge"
                    auto-complete="off"
                    placeholder="请输入卡充值手续费"
                ></el-input>
                </el-form-item>
                <el-form-item label="交易退款手续费" prop="refund" >
                <el-input
                    size="small"
                    v-model="addForm.refund"
                    auto-complete="off"
                    placeholder="请输入交易退款手续费"
                ></el-input>
                </el-form-item>
                <el-form-item label="小额交易费(常规卡) " prop="auth" >
                  <el-input
                    size="small"
                    v-model="addForm.auth"
                    auto-complete="off"
                    placeholder="请输入交易手续费(常规卡)"
                  ></el-input>
                </el-form-item>
                <el-form-item label="小额交易费(共享卡) " prop="shareAuth" >
                  <el-input
                    size="small"
                    v-model="addForm.shareAuth"
                    auto-complete="off"
                    placeholder="请输入小额交易费(共享卡)"
                  ></el-input>
                </el-form-item>  

                <el-form-item label="共享卡交易费" prop="transactionFee" >
                  <el-input
                    size="small"
                    v-model="addForm.transactionFee"
                    auto-complete="off"
                    placeholder="请输入共享卡交易费"
                  ></el-input>
                </el-form-item>
            <el-form-item label="月租服务费" prop="coverCharge" >
              <el-input
                  size="small"
                  v-model="addForm.coverCharge"
                  auto-complete="off"
                  placeholder="请输入月租服务费"
              ></el-input>
            </el-form-item>

            <el-form-item label="跨币种手续费" prop="crossCurrencyFee" >
              <el-input
                  size="small"
                  v-model="addForm.crossCurrencyFee"
                  auto-complete="off"
                  placeholder="请输入跨币种手续费"
              ></el-input>
            </el-form-item>
 
            <el-form-item label="备注" prop="remark" >
            <el-input
                size="small"
                v-model.trim="addForm.remark"
                auto-complete="off"
                type="textarea"
                :rows="5"
                placeholder="请输入备注"
            ></el-input>
            </el-form-item> 

        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button size="small" @click="closeDialog">取消</el-button>
            <el-button
            size="small"
            type="primary"
            :loading="loading"
            class="title"
            @click="submitForm('addForm')"
            >提交</el-button
            >
        </div>
        </el-dialog>


    </div>

    <div v-else>
      <userItem
        @changUser="changUser"
        :isUser="isUser"
        :uitemInfo="uitemInfo"
        :fatherName="fatherName"
      ></userItem>
    </div>
    <codeChoose ref="codeRef" :fromType="verType" @setParam="getParam" ></codeChoose>
  </div>
</template>

<script>
import { mapState, mapGetters } from "vuex";
import codeChoose from '@/components/codeChoose.vue'
import {
  setStoreS,
  getStoreS,
  removeStoreS,
  insertCharacter,
  spStr,
  timestampToTime,
} from "../../utils/util";
import {
  baseURL,
  req,
  reqJson,
  encrypt,
  decrypt,
  reqtoken,
  service,
  format,
  getUrl,
} from "../../api/axiosFun";
import Pagination from "../../components/Pagination";
import userItem from "./userItem.vue";
export default {
  data() {
    return {
      isUser: true,
      loading: false,
      disabled: false,
      addFormVisible: false,
      addFormVisiblePei: false, 
      
      resetFormVisible: false,
      shareFormVisible: false,
      cutFormVisible: false,
      b: format,
      timestampToTime: timestampToTime,
      fatherName: "会员管理",
      statusData: [
        { key: "未认证", value: 0 },
        // { key: "未认证", value: 1 },
        { key: "认证成功", value: 2 },
      ],
      statusJson: [
        { key: "未认证", value: 0 },
        { key: "未认证", value: 1 },
        { key: "认证成功", value: 2 },
      ],
      uitemInfo: "",
      addForm: {
        amount: "",
        remark: "",
        userId: "",
        rechargeAmount:''
      },
      cutForm: {
        amount: "",
        remark: "",
        userId: "",
        rechargeAmount:''
      },
      rulesReset: {
        password: [
          { required: true, message: "请输入新密码", trigger: "blur" },
        ],
        confirmPassword: [
          { required: true, message: "请再次确认密码", trigger: "blur" },
        ],
      },
      rulesShare: {
        shareCardCount: [
          {
            required: true,
            message: "请输入可开通共享卡数量",
            trigger: "blur",
          },
          {
            pattern: /^\d+$/,
            message: "请输入正确的数量",
            trigger: "blur",
          },
        ],
      },
      // rules表单验证
      rulesAdd: {
        amount: [
          { required: true, message: "到账金额", trigger: "blur" },
          {
            pattern: /^[0-9]+(\.\d{1,2})?$/,
            message: "请输入正整数或者2位数小数",
            trigger: "blur",
          }, 
        ],
        rechargeAmount: [
          { required: true, message: "充值金额", trigger: "blur" },
          {
            pattern: /^[0-9]+(\.\d{1,2})?$/,
            message: "请输入正整数或者2位数小数",
            trigger: "blur",
          }, 
        ], 

      },
      rulesCut: {
        amount: [
          { required: true, message: "请输入扣款金额", trigger: "blur" },
          {
            pattern: /^[0-9]+(\.\d{1,2})?$/,
            message: "请输入正整数或者2位数小数",
            trigger: "blur",
          },
        ],
        remark: [{ required: true, message: "请输入备注", trigger: "blur" }],
      },
      rules: {
        auth: [
          { required: true, message: "请输入小额交易费(常规卡)", trigger: "blur" },
          {
            pattern: /^[0-9]+(.[0-9]{1,2})?\%?$/,
            message: "请输入数字(两位小数)或者百分数",
            trigger: "blur",
          },
        ],
        transactionFee: [
          { required: true, message: "请输入共享卡交易费", trigger: "blur" },
          {
            pattern: /^[0-9]+(.[0-9]{1,2})?\%?$/,
            message: "请输入数字(两位小数)或者百分数",
            trigger: "blur",
          },
        ], 

        coverCharge: [
          { required: true, message: "请输入月租服务费", trigger: "blur" },
          {
            pattern: /^[0-9]+(\.\d{1,2})?$/,
            message: "请输入正确的数字",
            trigger: "blur",
          },
        ],
        crossCurrencyFee: [
          { required: true, message: "请输入跨币种手续费", trigger: "blur" },
          {
            pattern: /^[0-9]+(\.\d{1,2})?$/,
            message: "请输入正确的数字",
            trigger: "blur",
          },
        ], 

        shareAuth: [
          { required: true, message: "请输入小额交易费(共享卡)", trigger: "blur" },
          {
            pattern: /^[0-9]+(.[0-9]{1,2})?\%?$/,
            message: "请输入数字(或两位小数)或者百分数",
            trigger: "blur",
          },
        ],
        name: [{ required: true, message: "请输入组名", trigger: "blur" }],
        open: [
          { required: true, message: "请输入开卡手续费", trigger: "blur" },
          {
            pattern: /^[0-9]+(.[0-9]{1,2})?\%?$/,
            message: "请输入数字(两位小数)或者百分数",
            trigger: "blur",
          },
        ],
        recharge: [
          { required: true, message: "请输入卡充值手续费", trigger: "blur" },
          {
            pattern: /^[0-9]+(.[0-9]{1,2})?\%?$/,
            message: "请输入数字(两位小数)或者百分数",
            trigger: "blur",
          },
        ],
        refund: [
          { required: true, message: "请输入交易退款手续费", trigger: "blur" },
          {
            pattern: /^[0-9]+(.[0-9]{1,2})?\%?$/,
            message: "请输入数字(两位小数)或者百分数",
            trigger: "blur",
          },
        ],
      },
      resetForm: {
        id: "",
        password: "",
        confirmPassword: "",
      },
      shareForm: {
        id: "",
        shareCardCount: "",
      },
      formInline: {
        pageNum: 1,
        pageSize: 10,
        authType: "",
        loginName: "",
        userId: "",
      },
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10,
      },
      hasPermission5:false,
      hasPermission6:false,
      hasPerDel:false,
      // hostname:"https://dev.novalinkpay.com/", 
        // hostname: 'https://vip.novalinkpay.com/',
      hostname: 'https://www.gwhalepay.com/', 

       verArry:[],
      verType:'',
      curItem:'', 
      userInfo: null,
      fd:''


    };
  },
  // 注册组件
  components: {
    Pagination,
    userItem,
    codeChoose
  },
  computed: {
    ...mapGetters(["getUser"]), 
  },
  watch: {
    getUser(newVal) {
      this.userInfo = JSON.parse(newVal);
      this.hasPermission5 = this.$hasPermission(this.userInfo,['common','user5','admin5','admin']) 
      this.hasPermission6 = this.$hasPermission(this.userInfo,['common','user6','admin6','admin']) 
      this.hasPerDel = this.$hasPermission(this.userInfo,['common','admin'])  
    },
  }, 

  created() {
    this.getdata(this.formInline);
    if(this.$store.state.user){
      this.userInfo = JSON.parse(this.$store.state.user);
      this.hasPermission5 = this.$hasPermission(this.userInfo,['common','user5','admin5','admin']) 
      this.hasPermission6 = this.$hasPermission(this.userInfo,['common','user6','admin6','admin']) 
      this.hasPerDel = this.$hasPermission(this.userInfo,['common','admin'])  
    } 
    this.getInfo()

  },
  methods: {
    getInfo() {
      service
        .get("/api/photon/getUserInfo", {})
        .then((res) => {
          this.loading = false;
          if (res.code == 0) {
            this.userInfo = res.data;
            this.$store.commit("user", JSON.stringify(res.data));
          } else {
            this.$message({
              type: "info",
              message: spStr(res.msg, "PhotonPay", ""),
            });
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
    }, 
    hasPermissionMethod(data) {
      // 调用全局公共方法
      if(this.$store.state.user){
        this.userInfo = JSON.parse(this.$store.state.user);
        return this.$hasPermission(this.userInfo,data) 
      }
      
    },
    // 配置 
    peizhi(name, row) { 
      this.addForm = row;   
      service
        .get("/api/admin/getRateConfigFloat/"+row.userId, {
          "userId": this.addForm.userId,
        })
        .then((res) => {
          this.loading = false;
          if (res.code == 0) { 
            this.addForm =   {
              ...this.addForm,
              ...res.data
            }; 
          } else {
            this.$message({
              type: "info",
              message: res.msg,
            });
          }
        })
        .catch((err) => {
          this.$message.error(spStr(err, "PhotonPay", ""));
      }); 
      this.addFormVisiblePei = true;
    }, 

    getParam(val,type){  
      this.headers = val ;  
      this.editSaveAuth()  
    },  
    editSaveAuth(){   
        let obj = {
          "auth":  this.addForm.auth,
          "coverCharge":  this.addForm.coverCharge,
          // "createAt": this.editForm?.auth,
          // "createBy": this.editForm?.auth,
          "id":  this.addForm.id,
          "open":  this.addForm.open,
          "recharge":  this.addForm.recharge,
          "refund":  this.addForm.refund,
          "remark":  this.addForm.remark,
          "shareAuth":  this.addForm.shareAuth,
          // "updateAt": " this.addForm?.auth,
          "userId": this.addForm.userId,
        } 
        reqJson('post',"/api/admin/editRateConfigFloat", obj,{
          headers:{
            ...this.headers
          }
        })   
        .then((res) => {
              this.loading = false;
              if (res.code == 0) {
                this.$message.success(res.msg);
                this.getdata(this.formInline);
                this.closeDialog();
                // this.addForm = res.data; 
              } else {
                this.$message({
                  type: "info",
                  message: res.msg,
                });
              }
            })
            .catch((err) => {
              this.$message.error(spStr(err, "PhotonPay", ""));
          });
    },


    submitForm(name) {
      this.$refs[name].validate((valid) => {
        if (!valid) return;
        this.loading = true;   
        if(this.userInfo&&this.userInfo.verifyApi){
            this.verArry =  this.userInfo.verifyApi.split(',');
          if(this.verArry.includes('/api/admin/editRateConfigFloat')){
            this.$refs.codeRef.openDialog();  
          }else{ 
            this.editSaveAuth();
          }
        }else{
          this.editSaveAuth();
        }   
        
      });
    },
 

    getdata(parameter) {
      let url = getUrl(parameter);
      service
        .get("/api/admin/getUserList" + url, {})
        .then((res) => {
          this.loading = false;
          if (res.code == 0) {
            this.listData = res.rows;
            this.pageparm.currentPage = this.formInline.pageNum;
            this.pageparm.pageSize = this.formInline.pageSize;
            this.pageparm.total = res.total;
          } else {
            this.$message({
              type: "info",
              message: res.msg,
            });
          }
        })
        .catch((err) => {
          this.loading = false;
          this.$message.error(spStr(err, "PhotonPay", ""));
        });
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.pageNum = parm.currentPage;
      this.formInline.pageSize = parm.pageSize;
      this.getdata(this.formInline);
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline);
    },
    changUser(k, row) {
      this.isUser = k;
      this.uitemInfo = row;
      if (k) {
        this.getdata(this.formInline);
      }
    },
    handleShare(index, row) {
      this.shareFormVisible = true;
      this.shareForm.id = row.userId;
    },
    handleEdit(index, row) {
      this.addForm.userId = row.userId;
      this.addFormVisible = true;
    },
    handleCut(index, row) {
      this.cutForm.userId = row.userId;
      this.cutFormVisible = true;
      this.uitemInfo = row;
    },
    handleReset(index, row) {
      this.resetFormVisible = true;
      this.resetForm.id = row.userId;
    },
    handleUser(index, row) {
      let title = "停用后该用户将无法使用,请问您确定要停用吗？",
        msg = "已取消停用",
        status = 1;
      if (row.status == 1) {
        title = "启用后该用户将正常使用,请问您确定要启用吗？";
        msg = "已取消启用";
        status = 0;
      }
      this.$confirm(title, "信息", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let obj = { status: status };
          service
            .post("/api/admin/editUserInfo/" + row.userId, obj)
            .then((res) => {
              if (res.code == 0) {
                this.getdata(this.formInline);
              } else {
                this.$message.error(res.msg);
                return;
              }
            })
            .catch((err) => {
              this.disabled = false;
              this.$message.error(spStr(err, "PhotonPay", ""));
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: msg,
          });
        });
    },
 

    delUser(index, row) {
      this.$confirm("删除后该用户将无法使用,请问您确定要删除吗？", "信息", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          let obj = { status: status };
          service
            .post("/api/admin/deleteUserInfo/" + row.userId)
            .then((res) => {
              if (res.code == 0) {
                this.getdata(this.formInline);
              } else {
                this.$message.error(res.msg);
                return;
              }
            })
            .catch((err) => {
              this.disabled = false;
              this.$message.error(spStr(err, "PhotonPay", ""));
            });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: msg,
          });
        });
    },
    submitFormAdd() {
      this.$refs.addForm.validate((valid) => {
        if (!valid) return;
        let url = getUrl(this.addForm);
        // this.disabled = true;
        service.post("/api/admin/supporterRecharge" + url).then((res) => {
          if (res.code == 0) {
            this.disabled = false;
            this.closeDialog("addForm");
            this.getdata(this.formInline);
          } else if (res.code == 500) {
            this.$message.error(spStr(res.msg, "PhotonPay", ""));
            return;
          }
        });
      });
    },
    submitFormCut() {
      this.$refs.cutForm.validate((valid) => {
        if (!valid) return;
        let url = getUrl(this.cutForm);
        this.disabled = true;
        // service
        //   .post("/api/admin/supporterWithhold" + url)
        
          reqJson('post',"/api/admin/supporterWithhold" + url,{ 
        },{
          headers:{
            ...this.headers
          }
        }) 
          .then((res) => {
            this.disabled = false;
            if (res.code == 0) {
              this.closeDialog("cutForm");
              this.getdata(this.formInline);
              this.$message.success('操作成功！');
            } else {
              this.$message.error(spStr(res.msg, "PhotonPay", ""));
              return;
            }
          })
          .catch((err) => {
            this.disabled = false;
            this.$message.error(spStr(err, "PhotonPay", ""));
          });
      });
    },
    submitFormReset() {
      this.$refs.resetForm.validate((valid) => {
        if (!valid) return;
        if (this.resetForm.password === this.resetForm.confirmPassword) {
          let obj = { password: encrypt(this.resetForm.password) };
          service
            .post("/api/admin/editUserInfo/" + this.resetForm.id, obj)
            .then((res) => {
              if (res.code == 0) {
                this.disabled = false;
                this.closeDialog("resetForm");
              } else {
                this.$message.error(res.msg);
                return;
              }
            })
            .catch((err) => {
              this.disabled = false;
              this.$message.error(err);
            });
        } else {
          this.$message.error("两次密码不一致，请重新输入！");
        }
      });
    },
    submitFormShare() {
      this.$refs.shareForm.validate((valid) => {
        if (!valid) return;
        let obj = { shareCardCount: this.shareForm.shareCardCount };
        service
          .post("/api/admin/editUserInfo/" + this.shareForm.id, obj)
          .then((res) => {
            if (res.code == 0) {
              this.disabled = false;
              this.getdata(this.formInline);
              this.closeDialog("shareForm");
            } else {
              this.$message.error(res.msg);
              return;
            }
          })
          .catch((err) => {
            this.disabled = false;
            this.$message.error(err);
          });
      });
    },
    // 关闭编辑、增加弹出框
    closeDialog(name) {
      if (name == "resetForm") {
        this.resetFormVisible = false;
        this.$refs.resetForm.resetFields();
      } else if (name == "cutForm") {
        this.cutFormVisible = false;
        this.$refs.cutForm.resetFields();
      } else if (name == "shareForm") {
        this.shareFormVisible = false;
        this.$refs.shareForm.resetFields();
      } else {
        this.addFormVisible = false;
        this.$refs.addForm.resetFields();
      }
      this.addFormVisiblePei = false;
    },
    changeSwitch(e,val){ 
      let obj = { agent: e==true?1:0 };
      service
          .post("/api/admin/editUserInfo/" + val.userId, obj)
          .then((res) => {
            if (res.code == 0) { 
              this.getdata(this.formInline);
              // this.closeDialog("shareForm");
            } else {
              this.$message.error(res.msg);
              return;
            }
          })
          .catch((err) => {
            // this.disabled = false;
            this.$message.error(err);
          }); 

    },
 
  },

  directives: {
    // 注册一个复制指令
    copy: {
      bind(el, { value }) {
        el.handler = () => {
          if (!value) {
            console.error('需要复制的内容不能为空'); 
            return;
          }
          const input = document.createElement('input');
          input.value = value;
          document.body.appendChild(input);
          input.select();
          document.execCommand('copy');
          document.body.removeChild(input);
          alert('复制成功！') 
        }; 
        el.addEventListener('click', el.handler);
      },
      unbind(el) {
        el.removeEventListener('click', el.handler);
      },
    },
  },

};
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
</style>

 
 